<ui:composition template="/WEB-INF/templates/main-template.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="sidebar">
		<ui:include src="/WEB-INF/templates/public-sidebar.xhtml" />
	</ui:define>
	<ui:define name="content">
		<h:form id="permissionForm">
			<h:panelGrid style="width: 100%">
				<h:outputText value="Permissions" styleClass="outputTextTitle" />
				
				<h:panelGrid style="width: 100%" rendered="#{not permissionsBean.NO_PERMISSIONS_FOUND}">
					<h:outputText value="Existing Permissions" styleClass="outputTextSubTitle" />
					<p:dataTable value="#{permissionsBean.permissions}" var="row" paginator="true" rows="5">
						<p:column headerText="Permission" >
							<h:outputText value="#{row.displayName}" />
						</p:column>
						<p:column headerText="Module" >
							<h:outputText value="#{row.module.moduleName}" />
						</p:column>
						<p:column headerText="Service" >
							<h:outputText value="#{row.service.displayName}" />
						</p:column>
						<p:column headerText="Resource" >
							<h:outputText value="#{row.resource.displayName}" />
						</p:column>						
					</p:dataTable>
				</h:panelGrid>
								
				<h:outputText value="No permission created." styleClass="outputLabelwamInformation" rendered="#{permissionsBean.NO_PERMISSIONS_FOUND and (not permissionsBean.renderNewPermissionPanel)}" />
				<p:commandButton value="Start Creating Permission" actionListener="#{permissionsBean.addNewPermissionButtonActionListener}" rendered="#{permissionsBean.NO_PERMISSIONS_FOUND and (not permissionsBean.renderNewPermissionPanel)}" update="@form" /> 
				
				<p:commandButton value="Add New Permission" actionListener="#{permissionsBean.addNewPermissionButtonActionListener}" rendered="#{not permissionsBean.NO_PERMISSIONS_FOUND and (not permissionsBean.renderNewPermissionPanel)}" update="@form" />
				
				<h:panelGrid style="margin: 10px 0; width: 100%;" rendered="#{permissionsBean.renderNewPermissionPanel}" id="newPermissionDetailPanel">
					<h:outputText value="New Permission Details" styleClass="outputTextSubTitle" />
					<h:panelGrid columns="4" style="width: 100%">
						<h:panelGroup>
							<h:outputText value="#{msg['module.lable']}" />
							<br />
							<p:selectOneMenu id="modulesMenu" value="#{permissionsBean.selectedModuleId}" styleClass="selectOneMenu168pxFixedWidth" >
								<f:ajax render="@form" listener="#{permissionsBean.moduleChangeListener}" ></f:ajax>
								<f:selectItem itemLabel="" itemValue=""/>
								<f:selectItems value="#{permissionsBean.modulesMap}" />
							</p:selectOneMenu>
							<p:watermark for="modulesMenu" value="Select Module" />  
						</h:panelGroup>
						
						<h:panelGroup>
							<h:outputText value="#{msg['servicename.label']}" />
							<br />
							<p:selectOneMenu id="servicesMenu" value="#{permissionsBean.selectedServiceId}" styleClass="selectOneMenu168pxFixedWidth" >
								<f:ajax render="@form" listener="#{permissionsBean.serviceChangeListener}"/>
								<f:selectItem itemLabel="" itemValue=""/>
								<f:selectItems value="#{permissionsBean.servicesMap}"/>
							</p:selectOneMenu>
							<p:watermark for="servicesMenu" value="Select Service" />  
						</h:panelGroup>
						
						<h:panelGroup>
							<h:outputText value="#{msg['resourcename.label']}" />
							<br />
							<p:selectOneMenu value="#{permissionsBean.selectedResourceId}" id="resourcesMenu" styleClass="selectOneMenu168pxFixedWidth" >
								<f:selectItem itemLabel="" itemValue=""/>
								<f:selectItems value="#{permissionsBean.resourcesMap}"/>
							</p:selectOneMenu>
							<p:watermark for="resourcesMenu" value="Select Resource" />  
						</h:panelGroup>
						
						<h:panelGroup>
							<h:outputText value="Permission" />
							<br />
							<p:selectOneMenu id="permissionMenu" styleClass="selectOneMenu168pxFixedWidth" value="#{permissionsBean.selectedPermission}">
								<f:selectItem itemLabel="" itemValue=""/>
								<f:selectItems value="#{permissionsBean.permissionsMap}" />
							</p:selectOneMenu>
							<p:watermark for="permissionMenu" value="Select Permission" />  
						</h:panelGroup>
						<h:panelGroup>
							<h:outputText value="Display Name" />
							<br />
							<p:inputText value="#{permissionsBean.permissionDisplayName}" id="displayName" styleClass="selectOneMenu168pxFixedWidth" />								
							<p:watermark for="displayName" value="Enter a display name" />						  
						</h:panelGroup>								 										
					</h:panelGrid>		
					<h:panelGrid columns="2">
						<p:commandButton value="Save Permission" actionListener="#{permissionsBean.savePermission}" update="@form" />
						<p:commandButton value="Discard" actionListener="#{permissionsBean.discard}" update="@form" />
					</h:panelGrid>			
				</h:panelGrid>
			</h:panelGrid>
			<p:growl id="growl" />
		</h:form>
	</ui:define>
</ui:composition>

